package projectmanagement.web;

import org.springframework.validation.Errors;

import projectmanagement.model.Project;

public class EnterProjectValidator implements
org.springframework.validation.Validator{

	public boolean supports(Class clazz) {
		return clazz.equals(Project.class);
	}

	public void validate(Object command, Errors errors) {
		Project project = (Project) command;
		if (project == null)
			return;

		String name = project.getName();
		
		if (checkSymbols(name)){
			errors.reject("error.task.illegal.character");
		}
		
		if (name == null || name.trim().length() == 0){
			errors.reject("error.project.name.required");
		}
	}
	
	private boolean checkSymbols(String s){
		if(s.contains(">") || s.contains("<") || s.contains("javascript")){
			return true;
		}
		return false;
	}

}
